package api_servers
{
	import UIFree.uif_app;

	public class pi_mailserver extends api_mailserver {
		private var _app: uif_app;
		
		public function pi_mailserver(app :uif_app) {
			_app = app;
			super(app);
		}

		override public function get secrets(): Object {
			return {441805:'3b0c9d411eb5c5dc252c9fe26d4da53a',	// Рабочая версия
					456998:'0653cbe9091b1c69647af268657e703b',	// Разработка
					526680:'7b8fdf4fb07e0bc6f821825b7e27aa42',	// Тестовая версия
					588137:'9513e1841b64ccb70449d91f3a27e785' 	// Сайтовая версия
//					,515638:'051ef2b095d5b88eb5b624474965ecb3'
					}
		} 
		
		public function getAlbums(uid: String, handler_:*, queryID:String=''): void {
	    	jsrHelper([
						{pn: "method", pv: "photos.getAlbums"},
						{pn: "uid", pv: uid},
						{pn: "session_key", pv: 'none'}
	    			], handler_, queryID);
		}
		
		public function getPhotos(uid: String, aid: String, handler_:*, queryID:String=''): void {
	    	jsrHelper([
						{pn: "method", pv: "photos.get"},
						{pn: "uid", pv: uid},
						{pn: "aid", pv: aid},
						{pn: "session_key", pv: 'none'}
	    			], handler_, queryID);
		}
		
	    override public function getFriends(uid: String, handler_:*, queryID:String='getFriends'): void {
	    	jsrHelper([
						{pn: "method", pv: "friends.getAppUsers"},
						{pn: "ext", pv: "1"},
	    			], handler_, queryID, true);
	    }
	    
	    public function getAllFriends(uid: String, handler_:*, queryID:String='getAllFriends'): void {
	    	jsrHelper([
				{pn: "method", pv: "friends.get"},
				{pn: "uid", pv: uid},
				{pn: "ext", pv: "1"},
			], handler_, queryID, true);

/*	    	if (_cache[queryID + uid]) handler_(_cache[queryID + uid]);
	    	else {
		    	var friends: Array;
		    	var app_fr: Array;
		    	var rCount: int = 0;
		    	
		    	function doReseive(): void {
		    		for (var i: int=0; i<friends.length; i++) {
		    			friends[i].isInstall = app_fr.some(function(elem:*, index:int, arr:Array): Boolean {
		    				return elem.uid == friends[i].uid; 
		    			});
		    		}
		    		if (handler_) handler_(friends);
		    		_cache[queryID + uid] = friends;
		    	}
		    	
		    	jsrHelper([
							{pn: "method", pv: "friends.get"},
							{pn: "uid", pv: uid},
							{pn: "ext", pv: "1"},
		    			], function(data: Object): void {
		    				friends = data as Array;
		    				rCount++;
		    				if (rCount == 2) doReseive();
		    			}, queryID, true);
		    			
		    	getFriends(uid, function(data: Object): void {
		    		app_fr = data as Array;
	   				rCount++;
	   				if (rCount == 2) doReseive();
		    	});
		    }*/
	    }
	    
	    override public function getProfiles(uids: String, handler_:*, fields: String='', queryID:String=''): void {
	    	jsrHelper([
						{pn: "method", pv: "users.getInfo"},
						{pn: 'uids', pv: uids}
	    			], handler_, queryID);
	    }
	    
/*	    public function hasAppPermission(permission: String, _handle: Function, queryID: String = 'hasAppPermission'): void {
	    	jsrHelper([
						{pn: "method", pv: "users.hasAppPermission"},
						{pn: "ext_perm", pv: permission}
	    			], _handle, queryID);
	    }
	   */
	    
	    public function openPayDialog(sms_price: Number, other_price: Number, 
	    							openFunc: Function, service_id: int = 2, 
	    							service_name: String = 'Пополнение баланса'): void {
			var params: Array = [
				{pn:'method', pv:'payments.openDialog'},
				{pn:'window_id', pv: this.vars['window_id']},
				{pn:'service_id', pv: service_id},
				{pn:'service_name', pv: service_name}
			];
			if (!((other_price == 0) && (sms_price == 0))) {
				if (other_price > 0) params.push({pn: 'other_price', pv: other_price * 100});
				else params.push({pn: 'sms_price', pv: sms_price});
				jsrHelper(params, function(data:*): void {
					openFunc();
				}, 'openPayDialog');
			}
	    }
	}
}